import {a,b,dateFtt} from "./utils";

const trueFalseRenderer = (scope, prop) => {
  if (scope.row[prop]) {
    return "<i class='fa fa-check' aria-hidden='true'></i>";
  } else {
    return "<i class='fa fa-times' aria-hidden='true'></i>";
  }
};

const dateRenderer = (scope, prop) =>{
  return dateFtt("yyyy年MM月dd日",new Date(scope.row[prop]));
}

// 按照key找到对应的row
// tableData是表格中的数据，key是id的键，refs是一组需要寻找的key
const findRowsByKeys = function(tableData, key, refs) {
  var ret = [];
  if(!(refs instanceof Array)) {
    refs = [refs];
  }
  for (let i = 0; i < refs.length; i++) {
     for (let j = 0; j < tableData.length; j++) {
       if (tableData[j][key] === refs[i]) {
         ret.push(tableData[j]); break;
       }
     }
  }

  return ret;
}

export {trueFalseRenderer, findRowsByKeys, dateRenderer};
